package com.umbr3lla.network.socket;

import java.awt.Image;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

import com.umbr3lla.network.INetworkLayer;


public class ClientSocketHandler implements INetworkLayer
{
	
	private boolean listening = true;
	private ClientConnectionListener ccl;
	
	
	public ClientSocketHandler() throws IOException
	{
		ccl  = new ClientConnectionListener();	
	}
	
	
	public void stopLayer(){
		listening = false;
	}

	public void startLayer() {
		System.out.println("Starting CCL");
		new Thread(ccl).start();
	}
	
	
	private class ClientConnectionListener implements Runnable
	{
		private ServerSocket serverSocket;
		
		public ClientConnectionListener() throws IOException
		{
			serverSocket = new ServerSocket(4444);
		}
		
		public void run() 
		{
			while(listening)
			{
				Socket newClientSocket=null;
				
				try {
					newClientSocket = serverSocket.accept();
				} catch (IOException e) {
					e.printStackTrace();
					continue;
				}
				
				System.out.println("Client Connected");
				new Thread(new ClientSocket(newClientSocket)).start();
			}
		}
		
	}


	public void sendCardImage(Image i, int uniqueID) {
		
	}



	public void sendGameCharacterId(String cardId, byte playerId) {
	}


	public boolean promptQuestion(String question, byte playerId) {
		return false;
	}
	
	
}
